package com.example.validatestudy.demos.algorithm.sort;

/**
 * @param
 * @version v1
 * @auther WANGZHENFANG004
 * @summary 选择排序
 * @since 2024 07 09 19 17
 */
public class SelectSort {

    public static void main(String[] args) {
        int[] arr = {30,40,60,10,20,50};
        arr = selectSort(arr);
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
    }

    public static int[] selectSort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            int x = arr[i];
            int m = i;
            for (int j = i+1; j < arr.length; j++) {
                if(x > arr[j]){
                    x = arr[j];
                    m = j;
                }
            }
            if(i < m){
                arr[m] = arr[i];
                arr[i] = x;
            }
        }
        return arr;
    }


}
